package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.AttrKey;
import com.atguigu.lease.model.entity.AttrValue;
import com.atguigu.lease.model.entity.RoomAttrValue;
import com.atguigu.lease.model.entity.RoomInfo;
import com.atguigu.lease.web.app.mapper.AttrKeyMapper;
import com.atguigu.lease.web.app.mapper.AttrValueMapper;
import com.atguigu.lease.web.app.mapper.RoomAttrValueMapper;
import com.atguigu.lease.web.app.service.AttrKeyService;
import com.atguigu.lease.web.app.service.AttrValueService;
import com.atguigu.lease.web.app.service.RoomAttrValueService;
import com.atguigu.lease.web.app.vo.attr.AttrValueVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author liubo
* @description 针对表【room_attr_value(房间&基本属性值关联表)】的数据库操作Service实现
* @createDate 2023-07-26 11:12:39
*/
@Service
public class RoomAttrValueServiceImpl extends ServiceImpl<RoomAttrValueMapper, RoomAttrValue>
    implements RoomAttrValueService{

@Autowired
AttrValueMapper attrValueMapper;
    @Autowired
    AttrKeyMapper attrKeyMapper;
    @Override
    public List<AttrValueVo> getAttrValueVo(Long id) {
        List<RoomAttrValue> roomAttrValues = super.list(new LambdaQueryWrapper<RoomAttrValue>().eq(RoomAttrValue::getRoomId, id));
        Set<AttrValueVo> attrValueVos = new HashSet<>();
        if (roomAttrValues != null) {
            roomAttrValues.forEach(roomAttrValue -> {

                AttrValueVo attrValueVo = new AttrValueVo();
                AttrValue attrValue = attrValueMapper.selectById(roomAttrValue.getAttrValueId());
                AttrKey attrKey = attrKeyMapper.selectById(attrValue.getAttrKeyId());
                BeanUtils.copyProperties(attrValue, attrValueVo);
                attrValueVo.setAttrKeyName(attrKey.getName());
                attrValueVos.add(attrValueVo);

            });
        }
        return new ArrayList<>(attrValueVos);
    }

}




